#include <bits/stdc++.h>

#define eb emplace_back
#define ep emplace
#define fi first
#define se second
#define in read<int>()
#define lin read<ll>()
#define rep(i, x, y) for(int i = (x); i <= (y); i++)
#define per(i, x, y) for(int i = (x); i >= (y); i--)

using namespace std;

using ll = long long;
using db = double;
using pii = pair < int, int >;
using vec = vector < int >;
using veg = vector < pii >;

template < typename T > T read() {
	T x = 0; bool f = 0; char ch = getchar();
	while(!isdigit(ch)) f |= ch == '-', ch = getchar();
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar();
	return f ? -x : x;
}

template < typename T > void chkmax(T &x, const T &y) { x = x > y ? x : y; }
template < typename T > void chkmin(T &x, const T &y) { x = x < y ? x : y; }

const int N = 5e5 + 10;
const int K = 55;

int fa[K][N << 1], siz[K][N << 1], n, m, q, k, lst[N], a[N], b[N], c[N], e[N];
vector < tuple < int, int, int > > pot;
vec vpot[N << 2];

void ins(int xl, int xr, int v, int o = 1, int l = 1, int r = q) {
	if(l == xl && xr == r) return vpot[o].eb(v), void(); int mid = l + r >> 1;
	if(xr <= mid) ins(xl, xr, v, o << 1, l, mid); else if(xl > mid) ins(xl, xr, v, o << 1 | 1, mid + 1, r);
	else ins(xl, mid, v, o << 1, l, mid), ins(mid + 1, xr, v, o << 1 | 1, mid + 1, r); 
}

int gf(int t, int x) { return fa[t][x] == x ? x : gf(t, fa[t][x]); }
void merge(int x, int y, int t) {
	x = gf(t, x), y = gf(t, y); if(x == y) return;
	if(siz[t][x] < siz[t][y]) swap(x, y); pot.eb(x, y, t);
	siz[t][x] += siz[t][y]; fa[t][y] = x;
}
void undo() {
	auto v = pot.back(); pot.pop_back();
	int x, y, t; tie(x, y, t) = v;
	siz[t][x] -= siz[t][y]; fa[t][y] = y;
}

void solve(int o = 1, int l = 1, int r = q) {
	int lsz = pot.size();
	for(auto v : vpot[o]) {
		int x = a[e[v]], y = b[e[v]], z = c[v];
		if(z) merge(x, y + n, z), merge(x + n, y, z);
	}
	if(l == r) {
		int x = a[e[l]], y = b[e[l]], z = c[l];
		if(gf(z, x) == gf(z, y)) puts("NO"), c[l] = lst[e[l]];
		else puts("YES"), lst[e[l]] = c[l];
	} else { int mid = l + r >> 1; solve(o << 1, l, mid); solve(o << 1 | 1, mid + 1, r); }
	while(pot.size() > lsz) undo();
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("1.in", "r", stdin);
#endif
	n = in, m = in, k = in, q = in;
	rep(j, 1, k) rep(i, 1, n) fa[j][i] = i, siz[j][i] = 1, siz[j][i + n] = 1, fa[j][i + n] = i + n;
	rep(i, 1, m) a[i] = in, b[i] = in, lst[i] = q + 1;
	rep(i, 1, q) e[i] = in, c[i] = in;
	per(i, q, 1) {
		if(lst[e[i]] - 1 > i) ins(i + 1, lst[e[i]] - 1, i);
		lst[e[i]] = i;
	}
	rep(i, 1, m) lst[i] = 0;
	solve(); return 0;
}
